﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using XKPlatform.Common;

namespace NestleMidEdn.Controllers
{
    public class QueryController : Controller
    {
        [Route("sysInterfaceButton/SysbuttonQuery")]
        public JsonResult SysbuttonQuery(Search search, Guid? FormID)
        {
            if (!FormID.HasValue)
                return Json(new { code = 1, msg = "非法操作" });

            QuerySuite querySuite = new QuerySuite("SysForm", "FormNo");
            querySuite.AddParam("FormID", "=", FormID);

            var table = SqlHelper.GetSingle(querySuite.SelectSql, querySuite.Params);
            LogHelper.SaveLog("getFormDataList===FormID:", querySuite.SelectSql + "====" + FormID);
            if (table == null || string.IsNullOrEmpty(table.ToString()))
                return Json(new { code = 1, msg = "非法操作" });

            var tableName = table.ToString();

            querySuite = new QuerySuite(tableName + " where description='1'", "*", search);

            DataSet ds = SqlHelper.Query(querySuite.LimitSql, querySuite.Params);

            return Json(new { code = 0, data = QuerySuite.ToDictionary(ds.Tables[0]), count = QuerySuite.DsCount(ds) });

        }
    }
}